/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cliente;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.rmi.AccessException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.logging.Level;
import java.util.logging.Logger;
import servidor.IServer;

/**
 *
 * @author rowsinner
 */
public class Cliente {
    public void comunicar(String ipServidor) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            Registry r = LocateRegistry.getRegistry(ipServidor, 1099);
            IServer s = (IServer) r.lookup("IServer");
            try {
                System.out.println("Escriba un msg para el servidor:sssssssssssss");
                String aux = br.readLine();    
                while (!aux.equals("pepe")){
                    s.printMensaje(aux);
                    aux = br.readLine();
                }
            } 
            catch (IOException ex) {
                Logger.getLogger(Cliente.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (NotBoundException ex) {
            Logger.getLogger(Cliente.class.getName()).log(Level.SEVERE, null, ex);
        } catch (AccessException ex) {
            Logger.getLogger(Cliente.class.getName()).log(Level.SEVERE, null, ex);
        } catch (RemoteException ex) {
            Logger.getLogger(Cliente.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
